﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Study.App_Code;

namespace Study.Ajax
{
    /// <summary>
    /// RequestProgressAsyncHandler 的摘要说明
    /// </summary>
    public class RequestProgressAsyncHandler : IHttpAsyncHandler
    {
        /// <summary>
        /// 保存异步处理状态信息的集合
        /// </summary>
        public static List<AsyncResult> AsyncResults = new List<AsyncResult>();

        public void ProcessRequest(HttpContext context)
        {

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            AsyncResult result = new AsyncResult(context, cb);
            AsyncResults.Add(result);
            return result;
        }

        public void EndProcessRequest(IAsyncResult result)
        {
            //保证集合中只用一个元素
            AsyncResults.Clear();
            AsyncResult ar = (AsyncResult)result;
            ar.Send();
        }
    }
}